//
//  FirstViewController.m
//  gee
//
//  Created by apple on 11-5-11.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "FirstViewController.h"
#import "CCString.h"
#import "RegisterViewController.h"

@implementation FirstViewController

@synthesize txt_username;
@synthesize txt_password;
@synthesize swi_checkRememberMe;
@synthesize btn_login;
@synthesize btn_clear;
@synthesize btn_toregister;
@synthesize btn_background;
@synthesize loggingOnUser;

#pragma mark
#pragma what

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    textField.delegate = self;
    [textField resignFirstResponder];
    return YES;

}
-(IBAction)resetLoginClick:(id)sender{
    txt_password.text = @"";
    txt_username.text = @"";     
}

-(void)dismis_the_keyboard{
    [txt_password resignFirstResponder];
    [txt_username resignFirstResponder];
}



-(IBAction)handleLogonClick:(id)sender
{
    [self dismis_the_keyboard];
    
	// get the values...
	NSString *username = self.txt_username.text;
	NSString *password = self.txt_password.text;

    
    if ([username is_blank_or_nil]|| [password is_blank_or_nil]) {
        NSLog(@"username or password is blank");
        //UIAlertView show
        
        //提示错误 
        UIAlertView *alert = [[UIAlertView alloc] 
                              initWithTitle:@"" 
                              message:@"用户名密码不能为空" 
                              delegate:self 
                              cancelButtonTitle:@"确定" 
                              otherButtonTitles:nil];
        [alert show];
        [alert release];
        
    }else{
        //NSLog(@"username is false");
        
        
        
        
        
    }
}//	
//	// valdiate...
//	SBErrorBucket *bucket = [[SBErrorBucket alloc] init];
//	if(username == nil || username.length == 0)
//		[bucket addError:@"Username is required"];
//	if(password == nil || password.length == 0)
//		[bucket addError:@"Password is required"];
//	
//	// now what?
//	if(!(bucket.hasErrors))
//	{
//        // store for future use...
//		self.loggingOnUser = username;
//        
//		// we'll do the logon operation in here...
//		SBUsersService *users = [[SBUsersService alloc] init];
//		[users logon:username password:password callback:(SBLogonCallback *)self];
//		[users release];
//	}
//	else
//		[SBMessageBox show:bucket.errorsAsString];
//	
//	// cleanup...



- (void)viewDidLoad
{
    
//    UIControl *backGroundControl = [[UIControl alloc] initWithFrame:
//                                    CGRectMake(0, 0, 320, 480)];
//    backGroundControl.backgroundColor = [UIColor clearColor];
//    [backGroundControl addTarget:self 
//                          action:@selector(backgroundTap)
//                forControlEvents:UIControlEventTouchUpInside];
//    [self.view  addSubview:backGroundControl];
//    
//    
//    
    
    [super viewDidLoad];
 
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}


- (void)viewDidUnload
{
    txt_username          =nil;
    txt_password          =nil;
    swi_checkRememberMe    =nil;
    btn_login               =nil;
    btn_clear               =nil;
    btn_toregister         =nil;
    
    loggingOnUser  = nil;
    
    btn_background = nil;
    
    [super viewDidUnload];

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(IBAction)backgroundTap:(id)sender{
    [self dismis_the_keyboard];
}


-(IBAction)handle_register_click:(id)sender{

    RegisterViewController *register_view_controller = 
    [[[RegisterViewController alloc] init]autorelease ];
    [self presentModalViewController:register_view_controller animated:TRUE];

}
- (void)dealloc
{
    [txt_username           release];
    [txt_password           release];
    [swi_checkRememberMe    release];
    [btn_login              release];
    [btn_clear              release];
    [btn_toregister         release];
    
    [loggingOnUser          release];

    [btn_background        release];
    [super dealloc];
}

@end
